package live.zs.services;

import io.quarkus.runtime.StartupEvent;
import io.vertx.mutiny.core.Vertx;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;

/**
 * @author madison
 * @description
 * @date 2022/2/10 18:10
 */
@ApplicationScoped
public class RedService {
    @ConfigProperty(name = "red-service-port", defaultValue = "9001")
    int port;

    /**
     * Start an HTTP server for the red service.
     * Note: this method is called on a worker thread, and so it is allowed to block.
     *
     * @param ev
     * @param vertx
     */
    public void init(@Observes StartupEvent ev, Vertx vertx) {
        vertx.createHttpServer().requestHandler(req -> req.response().endAndForget("Hello from Red!"))
                .listenAndAwait(port);
    }
}
